var windowManfredi = {
	archive : {},
	getObject : function(id,title,txt){
		///this.archive[id] = undefined;
		if (this.archive[id] === undefined) {
			this.archive[id] = new this.cp(id,title,txt);
		}
		else
		{
			this.archive[id].set(title,txt);
		}
		return this.archive[id];
	},
	delObject: function(id){
		if(this.archive[id]){
			delete this.archive[id];
		}
	}
};
windowManfredi.cp=function(id,title,txt, glob){
	this.window_id		=	id;
	this.window_title	=	title;
	this.window_txt		=	txt;//Функция
	this.window_parent  =   glob;
}
windowManfredi.cp.prototype = {
	_init:function(){
		

		this.window_parent = 1;
		
		var win = {};
		if (this.window_parent) 
			win = $("#win_"+this.window_id, parent.document);
		else
			win = $("#win_"+this.window_id);
		if(win.length){
			//alert("too");
			if(this.window_title != null){				
				if (this.window_parent)
				{
					if($("#win_"+this.window_id+"_title", parent.document).lenght){
						$("#win_"+this.window_id+"_title", parent.document).html(this.window_title);
					}else{
						var element = "<div id='win_"+this.window_id+"_title' class='title'>"+this.window_title+"</div>";
						$("#win_"+this.window_id+"_content", parent.document).append(element);
					}
				}
				else
				{
					if($("#win_"+this.window_id+"_title").lenght){
						$("#win_"+this.window_id+"_title").html(this.window_title);
					}else{
						var element = "<div id='win_"+this.window_id+"_title' class='title'>"+this.window_title+"</div>";
						$("#win_"+this.window_id+"_content").append(element);
					}
				}
			}
			if (this.window_parent)
			{
				$("#win_"+this.window_id+"_content", parent.document).html(this.window_txt);				
				$("#win_"+this.window_id+"_title", parent.document).html(this.window_title);				
				$("#win_"+this.window_id, parent.document).show();
			}
			else
			{				
				$("#win_"+this.window_id+"_content").html(this.window_txt);
				$("#win_"+this.window_id+"_title").html(this.window_title);
				$("#win_"+this.window_id).show();
			}
			
			
			
						
		}else{
								
			var element	= "<div id='win_"+this.window_id+"' class='wins'>";
				element+=(this.window_title != null)?"<div id='win_"+this.window_id+"_title' class='title'>"+this.window_title+"</div>" : "";
				element+= 	"<div id='win_"+this.window_id+"_content' class='content'>"+this.window_txt+"</div><div class='close'><a onclick=\"windowManfredi.getObject('"+this.window_id+"')._close()\" title='Закрыть окно'></a></div>";
				element+= "</div>";
			
			if (this.window_parent)
			{
				$("body", parent.document).append(element);
				$("#lock_frame", parent.document).show();
			}
			else
			{
				$("body").append(element);
				$("#lock_frame").show();
			}
					
			
			// Делаем окно драговым	
			try
  			{			
				new window_set_drag("win_"+this.window_id, "win_"+this.window_id+"_title");			
			}
			catch(err) {}
			
			
			
		}
		
		
		
				
		
		
		
		// Устанавливаем оконо по центру экрана
		if (this.window_parent) 
			win = $("#win_"+this.window_id, parent.document);
		else
			win = $("#win_"+this.window_id);
		
		
		try
		{
			var ox = win.width();
			var oy = win.height();
					
			/*
			ox = replacestr(ox, 'px', '');
			oy = replacestr(oy, 'px', '');			
			*/
		}
		catch(err)
		{
		}
				
				
		var wx = Math.floor(parent.document.body.clientWidth / 2)  - Math.floor(ox / 2 );
		var wy = Math.floor((Math.floor(parent.document.body.clientHeight / 2) - Math.floor(oy / 2 )) / 2) + $(window).scrollTop() ;				
		
		if (this.window_id == "levelUp") 
			wy += 90;
		if (this.window_id == "fightEnd") 
			wy += 90;
				


		win.css("left", wx+"px");
		win.css("top", wy+"px");				

		
	},
	_close:function(){
		//alert(this.window_id);
		$("#win_"+this.window_id).remove();
		windowManfredi.delObject(this.window_id);		
		$("#lock_frame").hide();		
	},
	set:function(title,conten){
		this.window_title	=	title;
		this.window_txt		=	conten;
		$("#win_"+this.window_id+"_content").html(this.window_txt);
		$("#win_"+this.window_id+"_title").html(this.window_title);
		$("#win_"+this.window_id).show();
	},
	getElementComputedStyle:function (elem, prop){
		if (typeof elem!="object") elem = document.getElementById(elem); 
	  	if (document.defaultView && document.defaultView.getComputedStyle)
	  	{
	    	if (prop.match(/[A-Z]/)) prop = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
	    	return document.defaultView.getComputedStyle(elem, "").getPropertyValue(prop);
	  	} 
	  	if (elem.currentStyle)
	  	{
	    	var i;
	    	while ((i=prop.indexOf("-"))!=-1) prop = prop.substr(0, i) + prop.substr(i+1,1).toUpperCase() + prop.substr(i+2);
	    	return elem.currentStyle[prop];
	  	}	   
	  return "";
	}
}
